package com.hulk.dryad.common.constant.enums;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.EnumSet;

/**
 * @author  lqx
 * @date 2019/10/26.
 * 操作员来源
 */
public enum OperatorSource {

    NORMAL("NORMAL", "OperatorSource_NORMAL"),
    RECOMMEND("RECOMMEND", "OperatorSource_RECOMMEND"),
    REPLACEREG("REPLACEREG", "OperatorSource_REPLACEREG"),;


    /**
     * 类型
     */
    @Getter
    private String type;
    /**
     * 描述
     */
    private String description;

    OperatorSource(String type, String description) {
        this.type = type;
        this.description = description;
    }

    public String getDesc() {
        return messageSource.getMessage(description, null, description, LocaleContextHolder.getLocale());
    }


    private MessageSource messageSource;

    public OperatorSource setMessageSource(MessageSource messageSource) {
        this.messageSource = messageSource;
        return this;
    }


    @Component
    public static class ReportTypeServiceInjector {

		@Resource
        private MessageSource messageSource;

        @PostConstruct
        public void postConstruct() {
            for (OperatorSource ec : EnumSet.allOf(OperatorSource.class)) {
                ec.setMessageSource(messageSource);
            }
        }
    }
}
